package nl.hanze.designpatterns.DAO.impl.db;

import java.util.Iterator;

import nl.hanze.designpatterns.DAO.LoginCredentialDAO;
import nl.hanze.designpatterns.domain.LoginCredential;

public class LoginCredentialsDaoImpl extends BaseDaoImpl implements LoginCredentialDAO {

	@Override
	public boolean isValid(LoginCredential logincredential) {
		boolean isValid = false;
		String query = "SELECT * FROM LoginCredential WHERE "
				+ "username='" + logincredential.getUserName() +
				"' AND password='" + logincredential.getPassword() +"'";
		try{
			getExecutor().openConnection();
			Iterator<LoginCredential>  it = getExecutor().getIterator(query, LoginCredential.class);
			// If there is found a match the Iterator will contain one row, if so, the account is valid
			if(it.hasNext())
				isValid = true;

			getExecutor().closeConnection();
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return isValid;
	}
	

}
